<!--  -->
<template>
  <div class="list">
    <!-- tab头部 -->
    <!-- v-if -->
    <ul class="tabs" v-if="ftabshow">
      <!-- 设置点击事件--触发不同的数据 -->
      <li
        v-for="(tabsdata, index) in tabsdatas"
        :key="tabsdata.id"
        @click="changeTabs(index)"
      >
        <h4>{{ tabsdata.title }}</h4>
        <span :class="activeIndex == index ? 'active' : ''">{{
          tabsdata.tips
        }}</span>
      </li>
    </ul>
    <!-- 商品展示部分 -->
    <!-- 加载 -->
    <div class="loading" v-if="showloading">
      <img src="@/assets/images/loading.gif" alt="" />
    </div>
    <div class="goods-list" v-else>
      <ul>
        <li
          v-for="productData in productDatas"
          :key="productData.id"
          @click="todetails"
        >
          <div class="goods-img">
            <img :src="productData.url" alt="" />
            <div class="title">
              {{ productData.title }}
            </div>
            <div class="current_price">
              <span
                ><em>￥</em>
                <span>{{ productData.shopPrice | setInt }}</span>
                <em>{{ productData.shopPrice | setFloat }}</em>
              </span>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      tabsdatas: [
        {
          id: 1,
          title: "精选",
          tips: "为你推荐",
        },
        { id: 2, title: "社区", tips: "新奇好物" },
        { id: 3, title: "新品", tips: "潮流上新" },
        { id: 4, title: "热卖", tips: "火热爆款" },
      ],
      productDatas: [
        {
          id: 1,
          title:
            "华帝【年度旗舰】Huawei/华为 Mate 9 6+128GB 4G智能手机限量抢 麒麟960芯片 徕卡双镜头",
          url: "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489108266095.jpg",
          shopPrice: "2333",
        },
        {
          id: 2,
          title:
            "华帝【年度旗舰】Huawei/华为 Mate 9 6+128GB 4G智能手机限量抢 麒麟960芯片 徕卡双镜头",
          url: "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489108266095.jpg",
          shopPrice: "3333",
        },
        {
          id: 3,
          title:
            "华帝【年度旗舰】Huawei/华为 Mate 9 6+128GB 4G智能手机限量抢 麒麟960芯片 徕卡双镜头",
          url: "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489108266095.jpg",
          shopPrice: "3333",
        },
        {
          id: 4,
          title:
            "华帝【年度旗舰】Huawei/华为 Mate 9 6+128GB 4G智能手机限量抢 麒麟960芯片 徕卡双镜头",
          url: "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489108266095.jpg",
          shopPrice: "3333",
        },
        {
          id: 5,
          title:
            "华帝【年度旗舰】Huawei/华为 Mate 9 6+128GB 4G智能手机限量抢 麒麟960芯片 徕卡双镜头",
          url: "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489108266095.jpg",
          shopPrice: "3333",
        },
        {
          id: 6,
          title:
            "华帝【年度旗舰】Huawei/华为 Mate 9 6+128GB 4G智能手机限量抢 麒麟960芯片 徕卡双镜头",
          url: "https://x.dscmall.cn/storage/images/201703/thumb_img/0_thumb_G_1489108266095.jpg",
          shopPrice: "3333",
        },
      ],
      // 设置tab切换的activeIndex
      activeIndex: 0,
      showloading: false,
    };
  },
  props: ["ftabshow"],
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    changeTabs(index) {
      this.activeIndex = index;
      // 使loading图标显示
      this.showloading = true;
      // 发送数据请求
      setTimeout(() => {
        console.log(this);
        this.showloading = false;
      }, 1000);
    },
    todetails() {
      this.$router.push("/details");
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
};
</script>
<style lang="less">
.list {
  width: calc(100% - 2rem);
  margin: 1rem;
  .tabs {
    display: flex;
    height: 4rem;
    padding: 1rem 0;
    justify-content: center;
    align-items: center;
    li {
      flex: 1;
      text-align: center;
      position: relative;
      h4 {
        font-size: 1.6rem;
        color: #333;
      }
      span {
        color: #666;
        width: 70%;
        margin-left: 10%;
        display: block;
        padding: 0.3rem;
        border-radius: 1rem;
      }
      .active {
        background: linear-gradient(-88deg, #ff4f2e, #f91f28);
        color: #fff;
      }
      &::after {
        content: "";
        position: absolute;
        height: 80%;
        width: 0.1rem;
        background-color: #ccc;
        right: 0;
        top: 10%;
      }
      &:last-child::after {
        height: 0;
      }
    }
  }
  .goods-list {
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      li {
        width: 17rem;
        height: 26rem;
        background-color: #fff;
        border-radius: 1rem;
        margin: 1rem 0;
        overflow: hidden;
        img {
          width: 17rem;
          height: 17rem;
        }
        .title {
          width: 90%;
          padding: 0 1rem;
          height: 4rem;
          //   多行文本省略号
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          font-size: 1.5rem;
          margin: 1rem 0;
        }
        .current_price {
          padding: 0 1rem;
          color: #e22c2c;
          font-weight: 700;
          span {
            font-size: 1.5rem;
            em {
              font-size: 1.05rem;
            }
          }
        }
      }
    }
  }
  .loading {
    text-align: center;
    img {
      width: 4rem;
    }
  }
}
</style>